<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/22
 * Time: 9:31
 */

namespace app\models;

use yii;

abstract class BaseModel
{
    public $table;


    /**插入数据
     * @param $data
     * @return int
     */
    public function insert($data)
    {
        try {
            return yii::$app->db->createCommand()->insert($this->table, $data)->execute();

        } catch (\Exception $e) {
            yii::error($e->getMessage());
            return false;
        }
    }

    /**更新操作
     * @param $data
     * @param $where
     * @return int|string
     */
    public function save($data, $where)
    {
        try {
            return yii::$app->db->createCommand()->update($this->table, $data, $where)->execute();
        } catch (\Exception $e) {
            yii::error($e->getMessage());
            return false;
        }
    }

    /**删除操作
     * @param $data
     * @return int|string
     */
    public function delete($data)
    {
        try {
            return yii::$app->db->createCommand()->delete($this->table, $data)->execute();
        } catch (\Exception $e) {
            yii::error($e->getMessage());
            return false;
        }
    }


    public abstract function all($where = [], $offset = false, $limit = false, $order = false);

    public abstract function one($where = []);
}